package main.role;

import java.util.ArrayList;
import java.util.List;

import main.util.ArrayUtil;
import main.util.SqlConstants;

import org.apache.poi.ss.usermodel.Row;

public class RoleAuthelement {
	/*public static int start=10;
	public static int end=17;*/
	public static Row firstRow=null;
	
	/*start-end 获取moduleId*/
	public static String getRoleSql(Row row,String authId,int start,int end){
		String module;
		module=authId.substring(3, 6);
		/*if(authId.matches("[0-9]{14,}+")){
		}else{
			return "";
		}*/
		
		end=end+1;
		
		List<String> roles=new ArrayList<String>();
		
		if(firstRow==null){
			firstRow=row.getSheet().getRow(0);
		}
		
		for(;start<end;start++){
			String role=SqlConstants.getColValue(row, start);
			if("".equals(role)){
				continue;
			}
			
			roles.add(SqlConstants.getColValue(firstRow, start));
		}
		
		return authrole(roles, authId,module);
	}
	
	public static String authrole(List<String> roles,String authId,String module){
		if(roles.size()<1){
			System.out.println("...................没有勾选："+authId);
			return "";
		}
		
		String sql="INSERT INTO t_ucp_roleauth (roleId,moduleId,authId) VALUES ";
		//可能有多个角色
		for(int i=0;i<roles.size();i++){
			String role=roles.get(i);
			if(role!=null && !"".equals(role)){
				role="('"+role+"','"+module+"','"+authId+"')";
				roles.set(i, role);
			}
			
		}
		return sql+ArrayUtil.conectArray(roles, ",")+";\n";
	}

}
